<?php


namespace Yond\LaravelDomain\Console\Traits;

use Illuminate\Console\Command;

/**
 * Trait OptionOrTrait
 * @mixin Command
 */
trait GetInputTrait
{
    protected function optionOrAsk($param, $question, $default = null)
    {
        $value = $this->option($param);
        if ($value == null) {
            $value = $this->ask($question, $default);
        }

        return $value;
    }

    protected function optionOrChoice($param, $question, array $choices, $default = null, $attempts = null, $multiple = false)
    {
        // Check if we have already have a param set
        $value = $this->option($param);
        if ($value == null) {
            // There was no value provided via CLI, so ask the user..
            $value = $this->choice($question, $choices, $default, $attempts, $multiple);
        }

        return $value;
    }

    protected function optionOrConfirm($param, $question, $default = false)
    {
        // Check if we have already have a param set
        $value = $this->option($param);
        if ($value === null) {
            // There was no value provided via CLI, so ask the user..
            $value = $this->confirm($question, $default);
        }

        return $value;
    }

}